package com.simple.portal.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.portal.dao.IRightInfoDAO;
import com.simple.portal.vo.RightInfoVO;
import com.simple.util.common.Constants;

@Repository("rightInfoDAO")
public class RightInfoDAOImpl extends BaseDAO implements IRightInfoDAO{

	@Override
	public RightInfoVO findById(final String id) {
		return (RightInfoVO)super.get(RightInfoVO.class, id);
	}

	@Override
	public void save(final RightInfoVO rightInfoVO) {
		super.save(rightInfoVO);
	}

	@Override
	public void update(final RightInfoVO rightInfoVO) {
		super.update(rightInfoVO);
	}
	
	@Override
	public List<RightInfoVO> findAll() {
		return super.query(RightInfoVO.class);
	}

	@Override
	public void delete(final RightInfoVO rightInfoVO) {
		super.delete(rightInfoVO);
	}

	@Override
	public void delete(final String id) {
		super.delete(RightInfoVO.class, id);	
	}
	
	
	public List <RightInfoVO> findRightInfoVOListByAuthorize(final String groupId){
		
		 List<String> paramList = new ArrayList<String>();
		 paramList.add(groupId);
		 paramList.add(Constants.GROUP_RIGHT_FLAG_AUTHORIZATION);
		 final StringBuffer sb = new StringBuffer(300);
	        
	        sb.append( "select r  from GroupRightRelVO  grr , RightInfoVO r, ");
	        sb.append("GroupInfoVO g  where r.rightId=grr.rightId  and  grr.groupId=g.groupId ");
	        sb.append(" and  g.groupId=? and grr.rightFlag = ?");
		return super.query(sb.toString(),paramList);
	}
	
	public List <RightInfoVO> findRightInfoVOListByOperation(final String groupId){
		 List<String> paramList = new ArrayList<String>();
		 paramList.add(groupId);
		 paramList.add(Constants.GROUP_RIGHT_FLAG_OPERATION);
		 final StringBuffer sb = new StringBuffer(300);
	        
	        sb.append( "select r  from GroupRightRelVO  grr ,  RightInfoVO r ,");
	        sb.append(" GroupInfoVO g  where r.rightId=grr.rightId  and  grr.groupId=g.groupId ");
	        sb.append(" and  g.groupId=? and grr.rightFlag = ?");
	        
		return super.query(sb.toString(), paramList);
	}


}
